﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SMS.ServiceManager;
using digit.Core;
using SMS.Helper;
using SMS.Charts;
using SMS.UserManager;

namespace SMS.Admin.Modules
{
    public partial class ListStatOnline : WebControlBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ClientState.MemberInfo.UserType == 0 || ClientState.MemberInfo.UserType == 1 || ClientState.MemberInfo.UserType == 4 || ClientState.MemberInfo.UserType == 5)
            {
                //Nothing
            }
            else
                Response.Redirect("Default.aspx?module=Warning");
        }

        protected void btnStat_Click(object sender, EventArgs e)
        {
            this.BuildData(this.ddlServicID.SelectedValue);
        }

        private DataTable BuildData(string ServiceID)
        {
            DataTable dt = null;

            if (ddlMsgType.SelectedValue.ToLower() == "mo")
                dt = MessageInManager.StatisticMsgIn_ByServiceID_Online(ServiceID);

            else if (this.ddlMsgType.SelectedValue.ToLower() == "mt")
                dt = MessageOutManager.StatisticMsgOut_ByServiceID_Online(ServiceID);

            else if (this.ddlMsgType.SelectedValue.ToLower() == "cdr")
                dt = MessageOutManager.StatisticMsgCdr_ByServiceID_Online(ServiceID);

            if (dt != null && dt.Rows.Count > 0)
            {
                DataTable dtData = new DataTable();

                dtData.Columns.Add("name");
                dtData.Columns.Add("value");
                dtData.Columns.Add("text");
                dtData.Columns.Add("id");

                DataRow drData = null;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    drData = dtData.NewRow();

                    drData["name"] = dt.Rows[i]["RequestTime"].ToString();
                    drData["value"] = dt.Rows[i]["RowNo"].ToString();
                    drData["text"] = "Tổng số tin : " + dt.Rows[i]["RowNo"].ToString();
                    drData["id"] = "";

                    dtData.Rows.Add(drData);
                }

                return dtData;
            }
            else
            {
                this.lblError.Text = "Hiện tại chưa có số liệu thống kê tin.";
            }
            return null;
        }
    }
}
